'use strict';

const {Controller} = require('egg');
const ResponseUtil = require('../utils/ResponseUtil');
const HelperUtil = require('../utils/HelperUtil');
const StringUtil = require('../utils/StringUtil');
const Constant = require('../config/Constant');
const request = require('request');
const bankCardList = require('../config/bank/bankCardList');
class BankController extends Controller {


    async getBankCardList(){
        let {keyword} = this.ctx.query;

        let hots = bankCardList[0].bankData.map(bank => bank.text);

        let data = bankCardList[0].bankData.slice(); // 先复制第一个的 bankData

        bankCardList.forEach(item => {
            if (item.index_bar !== '热') {
                const filtered = item.bankData.filter(bank => !hots.includes(bank.text));
                data = data.concat(filtered);
            }
        });

        if(keyword){
            const regex = new RegExp(keyword, 'i'); // 忽略大小写
            data =  data.filter(bank => regex.test(bank.text));
        }

        return this.ctx.body = ResponseUtil.success(data);
    }

    async addBank(){
        const res = await this.ctx.service.bank.addBank();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async getBankList(){
        const res = await this.ctx.service.bank.getBankList();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async getBankDetail(){
        const res = await this.ctx.service.bank.getBankDetail();
        return this.ctx.body = ResponseUtil.success(res);
    }

}

module.exports = BankController;
